package tools;

import java.util.List;
import java.util.Vector;
import java.util.Random;

import datatypes.Vertex;

public class RandomVerticesGenerator {

    public static List<Vertex> randomVertices (double maxX, double maxY, double minDistance, int numVertices){
        Random generator = new Random();
        Vector<Vertex> vertices = new Vector<Vertex>();
        int f=1, t=0;
        double rx=0, ry=0;
        for (int i=0; i<numVertices; i++){
            while (f>0){
                f = 0;
                rx = maxX*(generator.nextDouble());
                ry = maxY*(generator.nextDouble());
                for (int j=0; j<vertices.size(); j++){
                    if (((vertices.get(j)).dist(new Vertex(rx,ry))) < minDistance){
                        f++;
                        t++;
                    }
                    if (t == 10000){
                        return null;
                    }
                }
            }
            vertices.addElement((new Vertex(rx,ry)));
            f = 1;
        }
        return vertices;
    }
}
